<template>
  <a-modal :maskClosable="false"
    :title="title"
    :width="1248"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-row><a-form-model ref="form" v-bind="layout" :model="model" :rules="validatorRules">
        <a-col span="15">
          <a-row>
            <a-col span="12">
              <a-form-model-item label="姓名" prop="realName">
                <a-input  v-model="model.realName"  placeholder="请输入姓名"/>
              </a-form-model-item>
            </a-col>
            <a-col span="12">
              <a-form-model-item label="性别" prop="sex">
                <a-radio-group v-model="model.sex" >
                  <a-radio :value="1">
                    男
                  </a-radio>
                  <a-radio :value="0">
                    女
                  </a-radio>
                </a-radio-group>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item label="电话" required prop="mobilePhone">
                <a-input placeholder="请输入电话" v-model="model.mobilePhone" />
              </a-form-model-item>
            </a-col>
            <a-col span="12">
              <a-form-model-item label="出生日期" >
                <a-date-picker placeholder="请输入出生日期" format="YYYY-MM-DD" valueFormat="YYYY-MM-DD" v-model="model.birthday" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item label="婚姻" required prop="izMarry">
                <a-select placeholder='请选择婚姻情况' v-model='model.izMarry'>
                  <a-select-option value='未婚'>未婚</a-select-option>
                  <a-select-option value='已婚'>已婚</a-select-option>
                  <a-select-option value='离异'>离异</a-select-option>
                  <a-select-option value='其他'>其他</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col span="12">
              <a-form-model-item label="职业" required prop="work">
                <a-input placeholder="请输入职业" v-model="model.work" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="12">
              <a-form-model-item label="身高(cm)" >
                <a-input-number placeholder="请输入身高" v-model="model.height" style="width: 200px"/>
              </a-form-model-item>
            </a-col>
            <a-col span="12">
              <a-form-model-item label="体重(kg)" >
                <a-input-number placeholder="请输入体重" v-model="model.weight" style="width: 200px"/>
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row justify="start">
            <a-form-item label="地址" required prop="address" :label-col="{span: 3 }"
                         :wrapperCol="{span: 20 }">
              <a-textarea v-model="model.address" style="height: 100px"></a-textarea>
            </a-form-item>

          </a-row>
        </a-col>
        <a-col span="9">
          <a-row>
            <a-form-model-item label="身份证" required prop="cardNo">
            <a-input placeholder="请输入身份证" v-model="model.cardNo" />
          </a-form-model-item>
          </a-row>
          <a-row>
            <a-form-model-item label="民族" required prop="nation">
              <j-dict-select-tag
                style="width: 95%;margin-left: 4px"
                placeholder="请选择频次"
                dictCode="nationality_type"
                v-model="model.nation" />
            </a-form-model-item>
          </a-row>
        </a-col>
      </a-form-model>
      </a-row>


    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@api/manage'
import { pushIfNotExist } from '@/utils/util'

export default {
  name: 'HHisPatientModal',
  components: {
  },
  data() {
    return {
      title: '操作',
      visible: false,
      model: {
        sex: '1',
      },
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 }
      },
      confirmLoading: false,
      validatorRules: {
        realName: [{ required: true, message: '请输入姓名!' }],
        sex: [{ required: true, message: '请选择性别!' }],
        mobilePhone: [{ required: true, message: '请输入电话!' }],
        birthday: [{ required: true, message: '请输入出生日期!' }],
        izMarry: [{ required: true, message: '请选择婚姻情况!' }],
        work: [{ required: true, message: '请输入职业!' }],
        address: [{ required: true, message: '请输入地址!' }],
        cardNo: [{ required: true, message: '请输入身份证!' }],
        nation: [{ required: true, message: '请选择民族!' }],
      },
      url: {
        add: '/his/patient/add',
      },
      loading: false,
    }
  },

  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      const that = this
      that.model = Object.assign({}, {  })
      that.visible = true
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          that.model.planType = '1'
          postAction(that.url.add, this.model).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    onSearch() {
      this.$refs.employeeModal.show()
      this.$refs.employeeModal.disableSubmit = false
    },
    onChange: function(e) {
      //社工
      if (e.target.value == '0') {
        this.$refs.butlerModal.show(false)
        this.$refs.butlerModal.disableSubmit = false
      } else {
        this.$refs.employeeModal.show()
        this.$refs.employeeModal.disableSubmit = false
      }
    },
    handleSignChoice(record) {
      if (this.model.execType == '1') {
        this.model.eyName = record.name
        this.model.eyId = record.id
      } else {
        this.model.eyName = record.name
        this.model.eyId = record.id
      }
    }
  }
}
</script>

<style scoped>

</style>